package com.example.fitnessservice.api.web;

import com.example.fitnessservice.module.pojo.CourseApply;
import com.example.fitnessservice.module.pojo.Result;
import com.example.fitnessservice.service.EnterForCampService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author feng
 * @version 1.0
 * @&#064;description: 个人操作申请和退款
 * @&#064;date 2022/11/27 19:34
 */
@RestController
@RequestMapping("/campDrop")
public class CampCourseDropController {
    @Autowired
    EnterForCampService enterForCampService;

    /*
    申请退课
     */
    @PutMapping("/{campCourseId}/{userId}")
    public Result submitApplication(String reason,
                                    @PathVariable Integer campCourseId,
                                    @PathVariable Integer userId
    ) {
        Result result = new Result();
        if (enterForCampService.submitApplication(reason, campCourseId, userId)) {
            result.setCode(200);
            result.setMsg("发送申请成功");
        } else {
            result.setCode(500);
            result.setMsg("发送申请失败");
        }
        return result;
    }
    /*
    根据需求查看我自己的申请
     */
    @GetMapping("/{applyStatus}/{userId}")
    public Result getPersonalApplyStatus(
            @PathVariable Integer userId,
            @PathVariable Integer applyStatus
    ) {
        Result result = new Result();

        result.setCode(200);
        List<CourseApply> applyList = enterForCampService.getPersonalApplyStatus(userId, applyStatus);
        if (!CollectionUtils.isEmpty(applyList)) {
            result.setMsg("获取申请成功");
            result.setData(applyList);
        }
        return result;
    }

    /*
    退款
     */
    @PutMapping("/{applyId}/{campCourseId}/{userId}")
    public Result returnMoney(@PathVariable Integer applyId,
                              @PathVariable Integer campCourseId,
                              @PathVariable Integer userId) {
        Result result = new Result();

        if (enterForCampService.returnMoney(applyId, campCourseId, userId)) {
            result.setMsg("退款成功");
            result.setCode(200);
        } else {
            result.setMsg("退款失败");
            result.setCode(500);
        }
        return result;
    }
}
